home *** CD-ROM | disk | FTP | other *** search
- unit WideQuery;
-
- interface
-
- // The InputQueryW function works like InputQuery, except it allows the
- // user to enter a wide string.
- // Copyright ⌐ 2000 Tempest Software, Inc.
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TInputQueryWForm = class(TForm)
- Label1: TLabel;
- Button1: TButton;
- Button2: TButton;
- procedure FormShow(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- private
- { Private declarations }
- fEditWnd: HWND;
- function GetText: WideString;
- procedure SetText(const Value: WideString);
- public
- { Public declarations }
- property EditWnd: HWND read fEditWnd;
- property Text: WideString read GetText write SetText;
- end;
-
- function InputQueryW(const Caption, Prompt: string; var Value: WideString): Boolean;
-
- implementation
-
- {$R *.DFM}
-
- function InputQueryW(const Caption, Prompt: string; var Value: WideString): Boolean;
- var
- Form: TInputQueryWForm;
- begin
- Form := TInputQueryWForm.Create(Application);
- try
- Form.Caption := Caption;
- Form.Label1.Caption := Prompt;
- Form.Text := Value;
-
- // Show the form modally so the user can edit the text.
- Result := Form.ShowModal = mrOK;
- if Result then
- Value := Form.Text;
- finally
- Form.Free;
- end;
- end;
-
- { TInputQueryWForm }
-
- procedure TInputQueryWForm.FormCreate(Sender: TObject);
- const
- Margin = 8;
- EditWidth = 300;
- begin
- // Create the wide edit control.
- fEditWnd := CreateWindowExW(Ws_Ex_ClientEdge, 'EDIT', '',
- Ws_Child or Ws_Visible or Ws_Border or Ws_TabStop or Es_AutoHScroll,
- Margin, Label1.BoundsRect.Bottom+Margin, EditWidth, Label1.Height + Margin,
- Handle, 0, hInstance, nil);
-
- // The default font uses the OEM character set, not Unicode.
- // The form uses Arial, which supports Unicode on NT.
- SendMessageW(EditWnd, Wm_SetFont, WParam(Font.Handle), 0);
- end;
-
- procedure TInputQueryWForm.FormDestroy(Sender: TObject);
- begin
- CloseWindow(EditWnd);
- end;
-
- // When the form opens, set the focus to the edit control.
- procedure TInputQueryWForm.FormShow(Sender: TObject);
- begin
- Windows.SetFocus(EditWnd);
- end;
-
- function TInputQueryWForm.GetText: WideString;
- begin
- // Get the text and return it to the caller.
- SetLength(Result, GetWindowTextLengthW(EditWnd));
- GetWindowTextW(EditWnd, PWideChar(Result), Length(Result)+1);
- end;
-
- procedure TInputQueryWForm.SetText(const Value: WideString);
- begin
- SetWindowTextW(EditWnd, PWideChar(Value));
- end;
-
- end.
-